package com.wontube.smr.bo.media;

import java.io.ByteArrayInputStream;
import java.io.IOException;

final class BitHelper {
	public static int read(long[] x, int length) {
		int r = (int) (x[0] >>> (64 - length));
		x[0] <<= length;

		return r;
	}
	
	public static void write(long[] x, int length, int value) {
		long mask = 0xFFFFFFFFFFFFFFFFL >>> (64 - length);
		x[0] = (x[0] << length) | ((long)value & mask);
	}

	public static void copyBytes(byte[] dst, int dstOffset, byte[] src) throws IOException {
		ByteArrayInputStream stream = new ByteArrayInputStream(src);
		try {
			stream.read(dst, dstOffset, src.length);
		} finally {
			stream.close();
		}
	}
}
